package com.example.wallet.controller;

import com.example.wallet.entity.Record;
import com.example.wallet.entity.ResultVO;
import com.example.wallet.service.IRecordService;
import com.example.wallet.vo.ChangeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class RecordController {
    @Autowired
    IRecordService recordService;

    /**
     * 查询用户钱包金额变动明细
     * @param userId 用户id
     * @return  变动记录集合
     */
    @GetMapping("/changeRecord")
    public ResultVO<List<Record>> changeRecord(@RequestParam("userId") Integer userId){
        List<Record> records = recordService.changeRecord(userId);
        return new ResultVO<>(200,"查询成功",records);
    }

    /**
     * 用户钱包金额修改
     * @param changeVo 具体操作
     * @return 成功的消息
     */
    @PutMapping("/updateBalance")
    public ResultVO<String> updateBalance(@RequestBody ChangeVo changeVo){
        String msg = recordService.change(changeVo);
        return new ResultVO<>(200,msg);
    }

}
